{include file="public/head"}

<body>
<div id="wrapper">

    <div class="gray-bg dashbard-1">
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <div class="form-horizontal m-t">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">商品名称：</label>
                                    <div class="col-sm-8">
                                        <input id="name" name="name" maxlength="255" type="text" class="form-control" required="" aria-required="true">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">商品简介：</label>
                                    <div class="col-sm-8">
                                        <input id="introduction" name="introduction" maxlength="500" type="text" class="form-control" required="" aria-required="true">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">商品类型：</label>
                                    <div class="col-sm-8">
                                        <select id="goods_type" name="goods_type" class="form-control">
                                            <!--<option value="1">普通商品</option>-->
                                            <!--<option value="2">升级商品</option>-->
                                            <option value="1">积分商品</option>
                                            <option value="2">礼包商品</option>
                                            <option value="3">复购商品</option>
                                            <option value="4">秒杀商品</option>
                                            <option value="5">拼团商品</option>
                                        </select>
                                    </div>
                                </div>
 <!--拼团   -->
 <div id="pin" style="display:none">
    <div class="form-group">
        <label class="col-sm-3 control-label">拼团券：</label>
        <div class="col-sm-8">
            <div class="input-group">
                <input id="quan" name="quan" type="text" class="form-control"  aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                <div class="input-group-addon">元</div>
            </div>
        </div>
    </div> 
    <div class="form-group">
        <label class="col-sm-3 control-label">拼团人数：</label>
        <div class="col-sm-8">
            <div class="input-group">
                <input id="allpeople" name="allpeople" type="text" class="form-control"  aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                <div class="input-group-addon">人</div>
            </div>
        </div>
    </div> 
    <div class="form-group">
        <label class="col-sm-3 control-label">拼到人数：</label>
        <div class="col-sm-8">
            <div class="input-group">
                <input id="getpeople" name="getpeople" type="text" class="form-control"  aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                <div class="input-group-addon">人</div>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">返还红包：</label>
        <div class="col-sm-8">
            <div class="input-group">
                <input id="backred" name="backred" type="text" class="form-control"  aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                <div class="input-group-addon">元</div>
            </div>
        </div>
    </div>
</div>
 <!--秒杀  -->
<div id="miao" style="display:none">
    <div class="form-group">
        <label class="col-sm-3 control-label">开始时间：</label>
        <div class="col-sm-8">
            <input id="btime" name="btime" maxlength="500" type="datetime-local" class="form-control" aria-required="true">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">结束时间：</label>
        <div class="col-sm-8">
            <input id="etime" name="etime" maxlength="500" type="datetime-local" class="form-control" aria-required="true">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">库存：</label>
        <div class="col-sm-8">
            <input id="mnum" name="mnum" maxlength="500" type="text" class="form-control" required="" aria-required="true">
        </div>
    </div>
</div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">商品分类：</label>
                                    <div class="col-sm-4">
                                        <select id="parent_id" class="form-control">
                                            <option value="0">选择父级分类</option>
                                            {volist name="ClassList" id="v"}
                                            <option value="{$v.id}">{$v.name}</option>
                                            {/volist}
                                        </select>
                                    </div>
                                    <div class="col-sm-4">
                                        <select id="son_id" class="form-control">
                                            <option value="0">选择子级分类</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">销售价：</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input id="price" name="price" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                                            <div class="input-group-addon">元</div>
                                        </div>
                                    </div>
                                </div>
<!--复购-->
<div id="jin" style="display:none">                                
    <div class="form-group">
        <label class="col-sm-3 control-label">会员价：</label>
        <div class="col-sm-8">
            <div class="input-group">
                <input id="hyprice" name="hyprice" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                <div class="input-group-addon">元</div>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">店铺价：</label>
        <div class="col-sm-8">
            <div class="input-group">
                <input id="dpprice" name="dpprice" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                <div class="input-group-addon">元</div>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">区县价：</label>
        <div class="col-sm-8">
            <div class="input-group">
                <input id="qxprice" name="qxprice" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                <div class="input-group-addon">元</div>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">市价：</label>
        <div class="col-sm-8">
            <div class="input-group">
                <input id="sjprice" name="sjprice" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                <div class="input-group-addon">元</div>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">省价：</label>
        <div class="col-sm-8">
            <div class="input-group">
                <input id="shprice" name="shprice" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                <div class="input-group-addon">元</div>
            </div>
        </div>
    </div>
</div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">商品单位：</label>
                                    <div class="col-sm-8">
                                        <input id="unit" name="unit" maxlength="50" type="text" class="form-control" placeholder="件" required="" aria-required="true">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">直推积分：</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input id="reward_1" name="reward_1" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                                            <div class="input-group-addon">元</div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">直推余额：</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input id="zhiyu" name="zhiyu" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                                            <div class="input-group-addon">元</div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">店铺奖励：</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input id="dian" name="dian" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                                            <div class="input-group-addon">元</div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">区县代级差：</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input id="xian" name="xian" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                                            <div class="input-group-addon">元</div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">市代级差：</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input id="shi" name="shi" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                                            <div class="input-group-addon">元</div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">省代级差：</label>
                                    <div class="col-sm-8">
                                        <div class="input-group">
                                            <input id="sheng" name="sheng" type="text" class="form-control" required="" aria-required="true" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" >
                                            <div class="input-group-addon">元</div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">是否包邮：</label>
                                    <div class="col-sm-8">
                                        <select id="is_bao" class="form-control">
                                            <option value="1">是</option>
                                            <option value="2">否</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">是否上架：</label>
                                    <div class="col-sm-8">
                                        <select id="is_shelf" class="form-control">
                                            <option value="1">下架</option>
                                            <option value="2">上架</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">是否推荐：</label>
                                    <div class="col-sm-8">
                                        <select id="is_recommend" class="form-control">
                                            <option value="1">否</option>
                                            <option value="2">是</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">商品Logo：</label>
                                    <div class="col-sm-8">
                                        <label for="logo_url">
                                            <img id="m_logo_url" src="__STATIC__/Admin/img/no_img.png" style="max-width:  80px">
                                            <input type="file" id="logo_url" class="upload_pic" style="display: none;">
                                        </label>
                                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> Logo尺寸：80*80</span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">商品相册：</label>
                                    <div class="col-sm-8">
                                        <label for="album_1">
                                            <img id="m_album_1" src="__STATIC__/Admin/img/no_img.png" style="max-width: 375px">
                                            <input type="file" id="album_1" class="upload_pic" style="display: none;">
                                        </label>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label"></label>
                                    <div class="col-sm-8">
                                        <label for="album_2">
                                            <img id="m_album_2" src="__STATIC__/Admin/img/no_img.png" style="max-width:  375px">
                                            <input type="file" id="album_2" class="upload_pic" style="display: none;">
                                        </label>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label"></label>
                                    <div class="col-sm-8">
                                        <label for="album_3">
                                            <img id="m_album_3" src="__STATIC__/Admin/img/no_img.png" style="max-width:  375px">
                                            <input type="file" id="album_3" class="upload_pic" style="display: none;">
                                        </label>
                                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 相册尺寸：375*375</span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">商品详情：</label>
                                    <div class="col-sm-8">
                                        <script id="detail" type="text/plain" style="width:100%;height:400px;"></script>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-3">
                                        <button class="btn btn-primary" type="button" id="sub">保存并添加</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


</div>
{include file="public/footer"}
<script type="text/javascript" src="__STATIC__/Admin/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/Admin/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__STATIC__/Admin/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>

<!--秒杀商品显示开始时间-->
<script>
    $(function() {
        $("#goods_type").change(function(){
            val = $(this).val();
            //秒杀
            if(val == 4){
                $("#miao").css('display','block'); 
            }else{
                $("#miao").css('display','none'); 
            }
            //复购
            if(val == 3){
                $("#jin").css('display','block'); 
            }else{
                $("#jin").css('display','none'); 
            }
            //拼团
            if(val == 5){
                $("#pin").css('display','block'); 
            }else{
                $("#pin").css('display','none'); 
            }
        });
    });
</script>

<script>
    var editor = new UE.ui.Editor();
    editor.render("detail");

    $('#son_id').hide();
    $('#parent_id').change(function(){
        $("#son_id").html('<option>选择子级分类</option>');
        $.ajax({
            type:"post",
            url:"{:url('Goods/SonChoose')}",
            data:'parent_id='+$('#parent_id').val(),
            dataType:"json",
            success:function(data){
                $('#son_id').show();
                $('#son_id').html(data);
            }
        });
    });

    //ajax异步图片上传
    $('.upload_pic').change(function(){
        //图片对象
        let that = $(this);
        var formData = new FormData();
        formData.append("image", that[0].files[0]);

        // 上传设置
        $.ajax({
            // 规定把请求发送到那个URL
            url: "{:url('Goods/forUpload')}",
            type: "post",            // 请求方式
            dtaType: 'json',
            data: formData,//传值就传fd对象了
            processData:false,  //告诉jQuery不要处理数据
            contentType: false,  //告诉jQuery不要设置contentType
            // 请求成功时执行的回调函数
            success: function (data) {
                if(data.status == 1)
                {
                    that.prev().attr('src',data.message);
                }
                else
                {
                    alert(data.message);
                }
            }
        });
    });

    //保存操作
    $("#sub").on('click',function(){
        var name = $('#name').val();    //商品名称
        var introduction = $('#introduction').val();    //商品简介
        var goods_type = $('#goods_type').val();    //商品类型
        // var goods_level = $('#goods_level').val();    //商品对应等级
        var parent_id = $('#parent_id').val();  //父级分类
        var son_id = $('#son_id').val();    //子级分类
        var price = $('#price').val();    //市场价
        var hyprice = $('#hyprice').val();    //会员价
        var unit = $('#unit').val();    //商品单位
        var reward_1 = $('#reward_1').val();    //一代奖励
        var dian = $('#dian').val();    //县代
        var xian = $('#xian').val();    //县代
        var shi = $('#shi').val();    //市代
        var sheng = $('#sheng').val();    //省代
        var is_shelf = $('#is_shelf').val();    //是否上架
        var is_recommend = $('#is_recommend').val();    //是否推荐
        var is_bao = $('#is_bao').val();    //是否包邮
        var dpprice = $('#dpprice').val();    
        var qxprice = $('#qxprice').val();    
        var sjprice = $('#sjprice').val();    
        var shprice = $('#shprice').val();    
        var logo_url = $('#m_logo_url').attr('src');  //Logo
        var album_1 = $('#m_album_1').attr('src');  //相册1
        var album_2 = $('#m_album_2').attr('src');  //相册2
        var album_3 = $('#m_album_3').attr('src');  //相册3
        var detail = editor.getContent();
        var btime = $('#btime').val();  
        var etime = $('#etime').val();  
        var mnum = $('#mnum').val(); 
        var quan = $('#quan').val(); 
        var allpeople = $('#allpeople').val(); 
        var getpeople = $('#getpeople').val(); 
        var backred = $('#backred').val(); 
        var zhiyu = $('#zhiyu').val(); 
        if(name == ''){
            layer.msg('请输入商品名称',{icon: 5,time:2000});
            return false;
        }

        if(introduction == ''){
            layer.msg('请输入商品简介',{icon: 5,time:2000});
            return false;
        }

        if(parent_id == 0){
            layer.msg('请选择父级分类',{icon: 5,time:2000});
            return false;
        }

        if(unit == ''){
            layer.msg('请输入商品单位',{icon: 5,time:2000});
            return false;
        }

        if(logo_url == '/static/Admin/img/no_img.png'){
            layer.msg('请上传商品Logo',{icon: 5,time:2000});
            return false;
        }

        if(album_1 == '/static/Admin/img/no_img.png' && album_2 == '/static/Admin/img/no_img.png' && album_3 == '/static/Admin/img/no_img.png'){
            layer.msg('请至少上传一张商品相册图片',{icon: 5,time:2000});
            return false;
        }

        if(album_1 == '/static/Admin/img/no_img.png'){
            var album_1 = '';
        }

        if(album_2 == '/static/Admin/img/no_img.png'){
            var album_2 = '';
        }

        if(album_3 == '/static/Admin/img/no_img.png'){
            var album_3 = '';
        }

        if(detail == ''){
            layer.msg('请添加商品详情',{icon: 5,time:2000});
            return false;
        }

        $.ajax({
            type:"POST",
            url:"{:url('Goods/GoodsAdd')}",
            data:{
                name:name,
                introduction:introduction,
                goods_type:goods_type,
                parent_id:parent_id,
                son_id:son_id,
                price:price,
                hyprice:hyprice,
                unit:unit,
                reward_1:reward_1,
                dpprice:dpprice,
                qxprice:qxprice,
                sjprice:sjprice,
                shprice:shprice,
                dian:dian,
                xian:xian,
                shi:shi,
                sheng:sheng,
                is_shelf:is_shelf,
                is_recommend:is_recommend,
                is_bao:is_bao,
                logo_url:logo_url,
                album_1:album_1,
                album_2:album_2,
                album_3:album_3,
                detail:detail,
                btime:btime,
                etime:etime,
                mnum:mnum,
                quan:quan,
                allpeople:allpeople,
                getpeople:getpeople,
                backred:backred,
                zhiyu:zhiyu,
            },
            dataType:"json",
            success:function(data){
                if(data.status == 1){
                    layer.msg(data.message, {icon: 6,time:2000},function () {
                        window.top.location.reload();
                    });
                }else{
                    layer.msg(data.message,{icon: 5,time:2000});
                }
            }
        });
    })
</script>

</body>

</html>
